using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.Testing.TestObjCtors;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.BPMN.Model
{
    [TestClass]
    public class BPMNElementVisualFactoryTest
    {
        private tDefinitions _tDefinitions;
        private BPMNShape _bpmnShape1;
        private BPMNShape _bpmnShape2;
        private BPMNElementVisualFactory _sut;

        [TestInitialize]
        public void SetUp()
        {
            _tDefinitions = new tDefinitionsCtor().Create();
            _bpmnShape1 = new BPMNShapeCtor().WithForBPMNElementHavingId("_1").Create();
            _bpmnShape2 = new BPMNShapeCtor().WithForBPMNElementHavingId("_2").Create();

            _sut = new BPMNElementVisualFactory();
        }

        [TestMethod]
        public void GetBPMNElementVisualById()
        {
            var tDefinitions = new tDefinitionsCtor().WithDiagramElement(_bpmnShape1, _bpmnShape2).Create();
            
            var actual = _sut.Create(tDefinitions);

            Assert.AreSame(_bpmnShape1, actual["_1"].TElement);
            Assert.AreSame(_bpmnShape2, actual["_2"].TElement);
        }

        [TestMethod]
        public void GetBPMNElementVisualById_in_case_of_BPMNDiagram_null()
        {
            _tDefinitions.BPMNDiagram = null;

            var actual = _sut.Create(_tDefinitions);
            
            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.Count);
        }

        [TestMethod]
        public void GetBPMNElementVisualById_in_case_of_BPMNDiagram_empty()
        {
            _tDefinitions.BPMNDiagram = new BPMNDiagram[0];

            var actual = _sut.Create(_tDefinitions);

            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.Count);
        }

        [TestMethod]
        public void GetBPMNElementVisualById_in_case_of_BPMNDiagram_BPMNPlane_null()
        {
            _tDefinitions.BPMNDiagram = new[] { new BPMNDiagram() };
            _tDefinitions.BPMNDiagram[0].BPMNPlane = null;

            var actual = _sut.Create(_tDefinitions);

            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.Count);
        }

        [TestMethod]
        public void GetBPMNElementVisualById_in_case_of_BPMNDiagram_BPMNPlane_DiagramElements_null()
        {
            _tDefinitions.BPMNDiagram = new[] { new BPMNDiagram() };
            _tDefinitions.BPMNDiagram[0].BPMNPlane = new BPMNPlane { DiagramElements = null };

            var actual = _sut.Create(_tDefinitions);

            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.Count);
        }

        [TestMethod]
        public void GetBPMNElementVisualById_in_case_of_BPMNDiagram_BPMNPlane_DiagramElements_empty()
        {
            _tDefinitions.BPMNDiagram = new[] { new BPMNDiagram() };
            _tDefinitions.BPMNDiagram[0].BPMNPlane = new BPMNPlane { DiagramElements = new DiagramElement[0] };

            var actual = _sut.Create(_tDefinitions);

            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.Count);
        }
    }
}